#include "ParticleSystem.h"
#include "Constants.h"

// -----------------------------------------------
//  BlockEmitter
// -----------------------------------------------
void BlockEmitter::createParticles(const ds::Vec3& startPosition,ds::Particles& particles) {
	int gx = startPosition.x;
	int gy = startPosition.y;
	ds::Vec2 pos = ds::Vec2(START_X + gx * SQUARE_SIZE,START_Y + gy * SQUARE_SIZE);
	for ( int x = 0; x < 4; ++x ) {
		for ( int y = 0; y < 4; ++y) {
			ds::Vec2 pp = pos;
			pp.x = pos.x + x * 8;
			pp.y = pos.y + y * 8;
			ds::Particle p;
			int offset = m_ColorIdx * 38;
			p.textureRect = ds::Rect(110,offset,8,8);
			p.position = ds::Vec3(pp.x,pp.y,0.0f);
			p.initialPosition = ds::Vec3(pp.x,pp.y,0.0f);
			p.size = ds::Vec3(8,8,0);			
			p.timer = 0.0f;
			int idx = x + y * 4;
			p.alive = true;
			p.ttl = 2.0f;
			ds::Vec2 vel = ds::math::getRadialVelocity(PARTICLE_ANGLES[idx],50.0f);
			p.velocity = ds::Vec3(vel.x,vel.y,0.0f);
			p.color = ds::Color(1.0f,1.0f,1.0f,0.6f);
			particles.append(p);
		}
	}
}
